package com.woniuxy;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Zx
 * @Description:
 * @Date 2021-03-22 19:31
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult<T> implements Serializable {
    private int code;
    private String msg;
    private T data;
    private Map<String, Object> info = new HashMap<String, Object>();

    public ResponseResult(T data) {
        this.data = data;
    }

    public ResponseResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(int code, String msg,T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseResult message(String msg) {
        this.setMsg(msg);
        return this;
    }

    public ResponseResult info(String key,Object value){
        this.info.put(key, value);
        return this;
    }

    public ResponseResult info(Map<String,Object> map){
        this.setInfo(map);
        return this;
    }

    public ResponseResult code(Integer code) {
        this.setCode(code);
        return this;
    }


    public static final ResponseResult<Void> SUCCESS = new ResponseResult(200, "ok");

    public static final ResponseResult<Void> ERR = new ResponseResult(500, "失败");
}
